//
//  FeedBackListVC.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2022/3/23.
//  Copyright © 2022 zwb. All rights reserved.
//

import UIKit

class ZyaFeedBackListVC: GlobalTableViewController {
    
   
  
    // MARK: - Life Cycle
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "意见反馈"
        
 
        self.tableView.mj_header = KSRefreshHeader {
            self.page = 1
            self.network()
        }
        self.tableView.mj_footer = KSRefreshFooter {
            self.page += 1
            self.network()
        }
        self.tableView.mj_header?.beginRefreshing()
        
  
    }
    
   
    
    
    
    // MARK: - Public Method
      func network() {
        
          KSNetwork.shared.doRequest(API.queryFeedbackInfo(page: "\(page)", size: "\(KSGlobal.pageSize)")) {[weak self] (data:BaseResult<FeedBaceModel>) in
            guard let `self` = self else { return }
            if data.flag == TRUE {
                if let infos = data.infos {
 
                    
                     if self.page == 1 {
                        self.dataArray.removeAll()
                     }
                      self.dataArray += infos
                     self.tableView.mj_header?.endRefreshing()
                    self.tableView.mj_footer?.endRefreshing()
                    if infos.count < KSGlobal.pageSize {
                        self.tableView.mj_footer?.endRefreshingWithNoMoreData()
                    }
              
                     self.tableView.reloadData()
                    
                }
            } else {
                KSToast(data.errorCombine.unwrap)
            }
        }
         
        
    }
    
   
    fileprivate var dataArray = [FeedBaceModel]()
    
}

// MARK: - TableView DataSource And Delegate
extension ZyaFeedBackListVC {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return dataArray.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: GlobalTableViewCell.identifier, for: indexPath) as!
        GlobalTableViewCell
        
        let one = dataArray[indexPath.row]
      
        let titleAndStatus = ("\(one.z_zb_title.unwrap)","")
         var contArr:[(String,String?)]!
   
            contArr = [("",one.z_content.unwrap)
                       ,("",one.z_create_tm.unwrap )
            ]
       
  
        cell.setDataSource(contentArr: contArr,titleAndStatus: titleAndStatus)
        
 
        return cell
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let vc = ZyaFeedbackFormVC()
        vc.one = self.dataArray[indexPath.row]
        vc.refreshClosure = {
            self.tableView.mj_header?.beginRefreshing()
        }
         vc.excuteType = .view
        navigationController?.pushViewController(vc, animated: true)
    }
}
